import random

import factory
import factory.fuzzy as fuzzy
from data.models import Client, Parking
from database import db


class ClientFactory(factory.alchemy.SQLAlchemyModelFactory):
    class Meta:
        model = Client
        sqlalchemy_session = db.session

    name = factory.Faker("first_name")
    surname = factory.Faker("last_name")
    credit_card = fuzzy.FuzzyText(length=12, chars="1234567890")
    car_number = fuzzy.FuzzyText(length=10)


class ParkingFactory(factory.alchemy.SQLAlchemyModelFactory):
    class Meta:
        model = Parking
        sqlalchemy_session = db.session

    address = fuzzy.FuzzyText()
    opened = factory.LazyAttribute(lambda x: random.choice([True, False]))
    count_places = factory.LazyAttribute(lambda x: random.randrange(50, 1000))
    count_available_places = factory.LazyAttribute(
        lambda o: random.randrange(0, o.count_places)
    )
